package com.modularity.project.view;

import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.modularity.camera.basic.base.CameraFragment;
import com.modularity.camera.basic.creator.CameraViewCreator;
import com.modularity.camera.basic.enums.CameraFace;
import com.modularity.camera.basic.enums.CameraType;
import com.modularity.camera.basic.listener.ICBTakePictureListener;
import com.modularity.common.base.BaseActivity;
import com.modularity.common.utils.managers.manager.ThreadManager;
import com.modularity.project.R;

import java.io.File;

public class CameraBasicActivity extends BaseActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_camera_basic);
//        CameraFragment fragment = CameraViewCreator.create(this, CameraFace.FACING_FRONT, CameraType.CAMERA2);
        CameraFragment fragment = CameraViewCreator.create_tv(1);
        fragment.setCustomPreview(true, fragment.getCustomPreviewSize());
        fragment.setCustomScaleX(true,-1f);
        fragment.setCustomRotate(true,180);
        if (null == savedInstanceState) {
            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.container_sub, fragment)
                    .commit();
        }
        ThreadManager.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                findViewById(R.id.container_sub).setVisibility(View.INVISIBLE);
            }
        });
        findViewById(R.id.btn_take).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                fragment.takePicture("", new ICBTakePictureListener() {
                    @Override
                    public void onTakePicture(File pictureFile) {
                        Log.i("jishen", pictureFile.getAbsolutePath());
                        ThreadManager.runOnUiThreadDelayed(new Runnable() {
                            @Override
                            public void run() {
                                findViewById(R.id.container_sub).setVisibility(View.VISIBLE);
                            }
                        },3000);
                    }
                });
            }
        });
        findViewById(R.id.btn_switch).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                fragment.switchCamera();
            }
        });
    }
}
